<template>
  <h1>循环指令</h1>
  <ul>
   <li v-for="item in 5">{{item}}</li>
  </ul>
  <hr>
  <ul>
    <li v-for="p in productArr">{{p}}</li>
  </ul>
  <hr>
  <table border="1px" align="center">
    <tr>
      <th>编号</th>
      <th>商品</th>
      <th>价格</th>
      <th>库存</th>
      <th>操作</th>
    </tr>
    <tr v-for="(p,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{p.title}}</td>
      <td>{{p.price}}</td>
      <td>{{p.num}}</td>
      <td><button @click="control(index)">删除</button></td>
    </tr>
  </table>
</template>

<script setup>
  import {ref} from "vue";

  const productArr = ref([
    {title:'苹果',price:50,num:100},
    {title:'香蕉',price:40,num:80},
    {title:'芒果',price:60,num:120},
    {title:'葡萄',price:30,num:60}
  ]);
  const control = (index)=>{
    if(confirm('请确认是否删除')){
      productArr.value.splice(index,1);
    }
  }
</script>

<style scoped>

</style>